package com.sale.succ.components.orders;

import java.util.ArrayList;

import com.sale.succ.datacomp.produce.ProduceListener;
import com.sale.succ.objects.OrderObj;
import com.sale.succ.system.txt.ObjectsProvider;



import eve.fx.Point;
import eve.ui.table.TableControl;

public class OrdersTable extends TableControl {
	private OrdersTableModel ordersModel;

	public OrdersTableModel getOrdersModel() {
		if (ordersModel == null) {
			ordersModel = new OrdersTableModel();
		}
		return ordersModel;
	}

	private ProduceListener listener;

	public OrdersTable(ProduceListener listener) {
		this.listener = listener;
		setTableModel(getOrdersModel());
		allowDragSelection = false;
		multiSelect = false;
	}
	
	public void notifyListener(ArrayList list, boolean updateSome) {
		listener.applyProduceDetails(list, updateSome);
	}

	public boolean canSelect(int row, int col) {
		if (row == -1)
			return false;
		return true;
	}

	public void penClicked(Point p) {
		int line = getSelectedLine();
		if (line == -1) {
			return;
		}
		Point cell = cellAtPoint(p.x, p.y, null);
		if (cell.y == -1)
			return;

		selectAndUpdate(cell.y, -1);

		OrderObj ob = getOrdersModel().getDataObject(cell.y);
		ArrayList list = new ArrayList();
		list.add(ObjectsProvider.getInstance().getTradeMarkCollection().get(ob.getTradeId()));
		list.add(getOrdersModel().getSum() + "");
		notifyListener(list, false);
	}
}
